 Vue.use(VueResource)
 new Vue({
   el: '#app',
   data: {
     userInfo: {
       name: '',
       password: '',
       confirmPassword: ''
     },
     rule: {
       password: /^[\w]{6,16}$/
     },
     layerOptions: {
       icon: 5,
       time: 1500,
       shade: [0.8, '#eee']
     }
   },
   methods: {
     register: function() {
       var user = this.userInfo
       if (!this.trim(user.name)) {
         return layer.msg('请输入用户名', this.layerOptions)
       }
       if (!user.password) {
         return layer.msg('请输入密码', this.layerOptions)
       }
       if (!this.rule.password.test(user.password)) {
         return layer.msg('密码为6-16位字母数字下划线组合', this.layerOptions)
       }
       if (user.password != user.confirmPassword) {
         return layer.msg('两次输入密码不一致', this.layerOptions)
       }
       this.$http.post('/user/register', this.userInfo).then(function(res) {
         if (res.data.code == 100) {
           layer.msg('注册成功！', {
             icon: 6,
             time: 1000
           })
           var user = res.data.data.user
           setTimeout(function() {
             localStorage.memoryClassUser = JSON.stringify({
               id: user.id,
               name: user.name
             })
             location.href = 'http://' + location.host
           }.bind(this), 1000)
         } else {
           layer.msg(res.data.msg, this.layerOptions)
         }
       })
     },
     trim: function(str) {
       return str.replace(/(^\s+)|(\s+$)/g, '')
     }
   }
 })